<template>
	<view class="container">
		<uv-tabs :list="list" :lineColor="`url(${lineBg}) 100% 100%`" :scrollable="false"></uv-tabs>
		<view class="list">
			<view class="list-item" @click="onDetails">
				<image src="@/static/images/index/line.png" class="line" mode="aspectFill"></image>
				<view class="left-image">
					<text class="price">¥300</text>
				</view>
				<view class="right">
					<view class="title">满100减10</view>
					<view class="date">2024-05-23</view>
					<view class="date">限购买XXX使用</view>
				</view>
			</view>
			<view class="list-item" @click="onDetails">
				<image src="@/static/images/index/line.png" class="line" mode="aspectFill"></image>
				<view class="left-image">
					<text class="price">¥300</text>
				</view>
				<view class="right">
					<view class="title">满100减10</view>
					<view class="date">2024-05-23</view>
					<view class="date">限购买XXX使用</view>
				</view>
			</view>
		</view>
		<uv-load-more :status="recommendList.status" />
	</view>
</template>

<script>
	import {
		getCouponInfo
	} from '@/common/api.js'
	const app = getApp();
	export default {
		data() {
			return {
				list: [{
					name: '可领取'
				}, {
					name: '待使用',
				}, {
					name: '已使用',
				}, {
					name: '已过期'
				}],
				lineBg: 'http://jy-nfc.oss-cn-hangzhou.aliyuncs.com/2024/12/24/f2a90c296f1e45e0898b994397da0d24.png',
				recommendList: {
					list: [],
					hasMore: false,
					loading: false,
					page: 1,
					status: 'loadmore'
				},
			};
		},
		onLoad(e) {
			this.getData()
		},
		onReachBottom() {
			if (this.recommendList.hasMore && !this.browseList.loading) {
				this.loadStatus = 'loading'
				this.getData().then((res) => {
					this.loadStatus = res.hasMore ? 'loadmore' : 'nomore'
				})
			}
		},
		methods: {
			getData() {
				return new Promise((resolve, reject) => {
					this.recommendList.loading = true
					let params = {
						pageNo: this.recommendList.page,
						pageSize: 10
					};
					getCouponInfo(params).then((result) => {
						let total = result.total;
						let data = result.rows;
						let {
							page,
							list,
							hasMore
						} = this.recommendList;
						list = [...list, ...data];
						if (page == 1) {
							hasMore = total > data.length;
						} else {
							hasMore = total > (page - 1) * 10 + data.length;
						}
						if (hasMore) {
							page++;
						} else {
							page = 1
						}
						resolve({
							data: data.length,
							hasMore
						});
						this.recommendList.page = page;
						this.recommendList.list = list;
						this.recommendList.loading = false;
					}).catch((err) => {
						this.recommendList.loading = false;
						reject();
					});
				});
			},
			newCoupon() {
				app.navigationTo('page_account/coupon/new')
			},
			click(item) {
				this.getData().then((res) => {
					this.loadStatus = res.hasMore ? 'loadmore' : 'nomore'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		overflow: hidden;
		min-height: 100vh;
		width: 100vw;
		padding: 22rpx;
		padding-bottom: calc(96rpx + 32rpx + 22rpx);
		box-sizing: border-box;
		background: #F7F8FA;

		.button-fb {
			position: fixed;
			bottom: 32rpx;
			left: 50%;
			transform: translateX(-50%);
			width: 480rpx;
			height: 96rpx;
			background: linear-gradient(180deg, #886AE6 0%, #4635FF 99%);
			border-radius: 48rpx;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 96rpx;
			text-align: center;
		}

		.list {
			// padding: 32rpx 24rpx;
			// box-sizing: border-box;

			.list-item {
				height: 204rpx;
				padding: 32rpx 24rpx;
				box-sizing: border-box;
				border-radius: 20rpx;
				background-image: url('@/static/images/index/discount.png');
				background-size: 100% 100%;
				display: flex;
				align-items: center;
				margin-bottom: 24rpx;
				position: relative;

				.line {
					width: 6.7rpx;
					height: 137rpx;
					position: absolute;
					right: 188rpx;
					top: 50%;
					transform: translateY(-50%);
				}

				.left-image {
					width: 188rpx;
					height: 188rpx;
					background-image: url('@/static/images/index/discount-bg.png');
					background-size: 100% 100%;
					border-radius: 12rpx;
					margin-right: 24rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					position: relative;

					.price {
						position: absolute;
						top: 40rpx;
						left: 50%;
						transform: translateX(-50%);
						font-weight: 700;
						font-size: 44rpx;
						line-height: 59rpx;
						color: #4635FF;
					}
				}

				.item-img {
					width: 128rpx;
					height: 128rpx;
					border-radius: 12rpx;
					margin-right: 24rpx;
				}

				.right {
					.title {
						font-weight: 700;
						font-size: 36rpx;
						color: #000000;
						line-height: 36rpx;
						margin-bottom: 16rpx;
					}

					.date {
						font-weight: 400;
						font-size: 28rpx;
						color: #86909C;
						line-height: 40rpx;
						margin-bottom: 8rpx;
					}
				}
			}
		}
	}

	/deep/.uv-tabs__wrapper__nav {
		// justify-content: space-between;
	}

	/deep/.uv-tabs__wrapper__nav__line {
		width: 64rpx !important;
		height: 24rpx !important;
		left: -10rpx;
		bottom: 10rpx;
	}
</style>